package cn.anquing.study.qlexpress.demo;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;

/**
 * 替换if then else 等关键字
 * @author wangquanqing
 * @since 2021/2/23 10:39
 */
public class Demo2 {

    public static void main(String[] args) throws Exception {
        ExpressRunner runner = new ExpressRunner();
        DefaultContext<String, Object> context = new DefaultContext<String, Object>();
        context.put("语文",1);
        context.put("数学",200);
        context.put("英语",70);
        runner.addOperatorWithAlias("如果", "if",null);
        runner.addOperatorWithAlias("则", "then",null);
        runner.addOperatorWithAlias("否则", "else",null);
        String express = "如果  (语文+数学+英语>270) 则 {return 1;} 否则 {return 0;}";
        Object r = runner.execute(express, context, null, true, true);
        System.out.println(r);
    }
}
